﻿<Table DataSource="data" OnChange="OnChange" TItem="Data">
  <PropertyColumn Property="c=>c.Id"
                  Sortable
                  Filterable />

  <PropertyColumn Property="c=>c.Name"
                  SorterCompare="@((a,b)=> string.Compare(a,b))"
                  SortDirections="new[] { SortDirection.Descending }"
                  Filterable />

  <PropertyColumn Property="c=>c.Address"
                  SorterCompare="@((a,b)=> string.Compare(a,b))"
                  SortDirections="new[] { SortDirection.Descending, SortDirection.Ascending }"
                  Filterable />

  <PropertyColumn Property="c=>c.BirthDate"
                  Format="yyyy/MM/dd"
                  Sortable
                  Filterable />

  <PropertyColumn Property="c=>c.IsActive"
                  Sortable
                  Filterable />

  <PropertyColumn Property="c=>c.Gender"
                  Sortable
                  Filterable />

  <PropertyColumn Property="c=>c.Hobbies"
                  Sortable
                  Filterable />
</Table>

@using AntDesign.TableModels;
@using System.Text.Json;
@using System;
@code {

  class Data
  {
    public Data(string name, string address, DateOnly? birthDate, bool isActive, Gender gender, Hobbies? hobbies)
    {
      Id = Guid.NewGuid();
      Name = name;
      Address = address;
      BirthDate = birthDate;
      IsActive = isActive;
      Gender = gender;
      Hobbies = hobbies;
    }

    public Guid Id { get; set; }
    public string Name { get; set; }
    public string Address { get; set; }
    public DateOnly? BirthDate { get; set; }
    public bool IsActive { get; set; }
    public Gender Gender { get; set; }
    public Hobbies? Hobbies { get; set; }
  }

  enum Gender
  {
    Male,
    Female
  }

  [Flags]
  enum Hobbies
  {
    Reading = 1,
    Sport = 2,
    Cooking = 4
  }

  Data[] data =
  {
        new("John Brown","New York No. 1 Lake Park",new DateOnly(1980,1,1),true,Gender.Male,Hobbies.Cooking | Hobbies.Reading),
        new("Sara Green","London No. 1 Lake Park",new DateOnly(1983,12,1),true,Gender.Female,Hobbies.Reading | Hobbies.Sport),
        new("Joe Black", "Sidney No. 1 Lake Park",new DateOnly(1977,11,1),true,Gender.Male,Hobbies.Cooking | Hobbies.Sport),
        new("Jim Red","London No. 2 Lake Park",new DateOnly(1985,1,1),false,Gender.Male,null),
  };

  void OnChange(QueryModel<Data> query)
  {
    Console.WriteLine(JsonSerializer.Serialize(query));
  }
}